home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Tools - Objects / Virtual User 1.0 / Example Scripts / MessagePassing Example / MessagePassingDemoLib.vu < prev    next >
Text File  |  1991-01-25  |  3KB  |  85 lines

  1. #
  2. #    File:        MessagePassingDemoLib.vu
  3. #
  4. #    Contains:    This is a demo library which is used by scripts Actor1.vu and
  5. #                Actor2.vu that run in parallel. They together demonstrate message 
  6. #                passing while sharing tasks in this library. To run this demo you need two 
  7. #                target machines (both having the Desk Accessory, Key Caps).
  8. #                It would be better if the two targets had different memory
  9. #                configurations and are running different versions of system software.
  10. #                Your command line should be as follows: (assuming the two 
  11. #                targets have user names as Target1 and Target2 and that
  12. #                Actor1.vu, Actor2.vu and the library MessagePassingDemoLib.vu
  13. #                are all in your current working directory)
  14. #                VU    -t1 '*:Target1' -s1 Actor1.vu -l1 Actor1.log ∂
  15. #                    -t2 '*:Target2' -s2 Actor2.vu -l2 Actor2.log
  16. #
  17. #    Caution:    Do not forget to turn the key repeat off in the control panel on both
  18. #                the targets. The script takes a few seconds before you start seeing
  19. #                anything on the target screens.
  20. #
  21. #    Written by:    P Nagarajan
  22. #
  23. #    Copyright:    © 1990 by Apple Computer, Inc., all rights reserved.
  24. #
  25. #    Change History:
  26. #
  27. #        8/16/90       naga         creation 
  28. #
  29. #    To Do:
  30. #
  31.  
  32. #### open a session with specified actor 
  33. task open_session(recipient)
  34. begin
  35.     status := '';
  36.     while not (status = 'open')
  37.     begin
  38.         status := openSession(recipient);
  39.     end;
  40. end; #open_session
  41.  
  42.  
  43. #task to show a message passing demo using key caps on the target machine
  44. task run_demo(fellow_actor)
  45. begin
  46.     if match[menuItem t:'Key Caps' m:1]
  47.     begin
  48.         select [menuItem t:'Key Caps' m:1];
  49.         wait(3);#for Key Caps to come up
  50.         type k:{"You are going to see the messages received from the ",
  51.                  "other actor (as is) in this window"};
  52.         wait(2);#to let the viewer read the typed sentence on target screen
  53.         type k:{returnKey};
  54.         my_name := actorName();
  55.         my_target := match[target];
  56.         my_target_name := my_target.t;
  57.         my_target_memory := (match[target]).r;
  58.         my_target_system := (match[system]).v;
  59.         dialogue := {    {"Hey I am : ", my_name,"Stop" },
  60.                         {"My purpose is to demonstrate message passing", "Stop"},
  61.                         {"The target under my control is ", my_target_name, "Stop"},
  62.                         {"My target has ", my_target_memory, " bytes of RAM", "Stop"},
  63.                         {"My target is running system ", my_target_system, "Stop"},
  64.                         {"Bye", "Stop"}    };
  65.         for each sentence in dialogue
  66.         begin
  67.             send(fellow_actor, sentence);
  68.             reply := receive(fellow_actor);
  69.             type k:{fellow_actor.t,": "};
  70.             while (reply <> 'Stop') 
  71.             begin
  72.                 wait(1); 
  73.                 #wait is used here to avoid tight loops,
  74.                 #and let other actors share time
  75.                 if reply type k:{reply};
  76.                 reply := receive(fellow_actor);
  77.             end;#while
  78.             wait(3);#to let the viewer read the typed sentence on target screen
  79.             type k:{returnKey};
  80.         end;#for each
  81.         close [window t:'Key Caps'];
  82.     end;#if key caps available
  83.     else println "sorry, cannot perform demo without Key Caps on my target";
  84. end;#run_demo
  85.